<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>记账</title>
<!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
<script src="libs/jquery-1.12.1.min.js"></script>
<link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
<script src="libs/handlebars.min.js" type="text/javascript"></script>
<script src="libs/d3.v3.min.js" type="text/javascript"></script>
<script src="libs/nv.d3.min.js" type="text/javascript"></script>
<link href="libs/nv.d3.min.css" rel="stylesheet">
</head>
<body>
	<div class="container">
		<div class="row">
			<div class="page-header">
				<h2>
					<strong>档案统计</strong>
				</h2>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="col-md-12">
			<ul class="nav nav-pills">
				<li><a href="index.html">首页</a></li>
				<li><a href="#">用户：<span id="nickname"></span></a></li>
				<button id="tuichu">用户退出</button>
			</ul>
		</div>
	</div>

	<div class="container">
		<div class="row">
			<div class="col-md-5">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<p>用户上传档案总数</p>
					</div>
					<div class="panel-body" id="list1"></div>
				</div>
			</div>
		</div>
		<div class="col-md-2 ">
			<div class="form-group">
				<label for="begin">起始时间</label> <input type="date"
					class="form-control" id="begin" />
			</div>
			<div class="form-group">
				<label for="end">结束时间</label> <input type="date"
					class="form-control" id="end" />
			</div>
			<button id="chaxun">查询</button>
		</div>
		<div class="container">
			<div class="row">
				<div class="col_md_12" id="chart">
					<p>
						<br />
					<hr />
					<strong>用户档案统计</strong>
					<svg style="height: 300px; width: 50%"></svg>
					<br>
					</p>
				</div>
			</div>
		</div>
	</div>
	<script type="text/x-handlebars-template" id="template">
    {{#each item}}
    <div class="panel panel-default col-md-3">
      <div class="panel-body">
        <dl>
          <dt>用户</dt> <dd>{{nick}}</dd>
          <dt>总和</dt> <dd>{{counter}}</dd>
       </dl>
     </div>
   </div>
   {{/each}}
 </script>
</body>
<script type="text/javascript">
	$(function() {
		$.getJSON('queryUsers.action', function(res) {
			$('#nickname').text(res.nk);
		})

		$('#tuichu').click(function() {
			$.post('tuichu.action', function(res, status) {
				if ('OK' == res) {
					alert('退出成功');
					window.location.href = 'login.html'
				}
				window.location.href = "login.html";
			});
		});
	$.getJSON('tongji.action', function(res) {
			var data = {
				'item' : res
			};
			var t = Handlebars.compile($('#template').html());
			$('#list1').html(t(data));
		})

		$.getJSON('tongji.action', function(res) {
			nv.addGraph(function() {
				var chart = nv.models.pieChart().x(function(d) {
					return d.nick
				}).y(function(d) {
					return d.counter
				}).showLabels(true).labelType('percent');
				d3.select("#chart svg").datum(res).transition().duration(350)
						.call(chart);
				return chart;
			})
		})

		$('#chaxun').click(
				function() {
					$.post('querytime.action', {
						begin : $('#begin').val(),
						end : $('#end').val()
					}, function(res, status) {
						nv.addGraph(function() {
							var chart = nv.models.pieChart().x(function(d) {
								return d.nick
							}).y(function(d) {
								return d.counter
							}).showLabels(true).labelType('percent');
							d3.select("#chart svg").datum(res).transition()
									.duration(350).call(chart);
							return chart;
						})
					});
				});
	})
</script>
</html>